<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>vue2的mixins - {{ count }} - <button @click="fn">btn</button></h2>
      <child></child>
    </div>

    <script src="./lib/vue2.js"></script>
    <script>
      // mixins混入
      // 创建一个混入对象
      // 混入对象里面就相当于是组件，但是不需要写template
      const myMixins = {
        data() {
          return {
            count: 1,
          };
        },
        methods: {
          fn() {
            this.count++;
          },
        },
      };

      const Child = {
        data() {
          return {
            name: "zhangsan",
            count: 10,
          };
        },
        mixins: [myMixins],
        template: `
          <div>这是child子组件 - {{ count }} - <button @click="fn">btn</button></div>
        `,
      };

      new Vue({
        mixins: [myMixins],
        components: {
          Child,
        },
      }).$mount("#app");
    </script>
  </body>
</html>
